package com.wind.cloud.common.exception;


import com.wind.cloud.common.constant.ErrorCodes;
import com.wind.cloud.common.i18n.MessageUtils;

/**
 * 业务异常
 *
 * @author wind.
 */
public class BusinessException extends RuntimeException implements IBusinessException {

    private Integer code = ErrorCodes.BUSINESS_ERROR;

    private String message;

    private Object[] params;

    public BusinessException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public BusinessException(Integer code, String message, Object... params) {
        super(message);
        this.code = code;
        this.message = message;
        this.params = params;
    }

    public BusinessException(String message) {
        super(message);
        this.message = message;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        if (params != null) {
            return MessageUtils.getMessage(message, params);
        } else {
            return MessageUtils.getMessage(message);
        }
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object[] getParams() {
        return params;
    }

    public void setParams(Object[] params) {
        this.params = params;
    }
}
